<!--
 * @Author: your name
 * @Date: 2020-02-25 13:32:39
 * @LastEditTime: 2020-03-19 13:47:30
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \福路德扫码系统\html\cksm.html
 -->
<!doctype html>
<html>

<head>
	<meta charset="utf-8">
	<meta name="viewport"
		content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0,viewport-fit=cover" />
	<meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
	<title>Hello APP</title>
	<link rel="stylesheet" type="text/css" href="../css/longPressRecording.css">
	<link rel="stylesheet" type="text/css" href="../css/vant.css">
	<link rel="stylesheet" type="text/css" href="../css/base.css" />
	<link rel="stylesheet" type="text/css" href="../css/local.css" />
	<script type="text/javascript" src="../script/jquery.js"></script>
	<script type="text/javascript" src="../script/layer/mobile/layer.js"></script>
	<script type="text/javascript" src="../script/vue.min.js"></script>
	<script type="text/javascript" src="../script/vant.min.js"></script>
	<script type="text/javascript" src="../script/fastclick.js"></script>
	<script type="text/javascript" src="../script/base.js"></script>
	<script type="text/javascript" src="../script/app-tree.js"></script>
	<style type="text/css">
		.part {
			padding: 15px 15px 0 15px;
		}

		.part .pf {
			border-radius: 6px;
			box-shadow: 0px 1px 5px rgb(200, 198, 198);
			background-color: #fff;
			overflow: hidden;
		}

		.textarea {
			display: block;
		}

		.label {
			padding: 10px 16px;
		}

		.ap-f {
			border-bottom: 1px solid #f7f7f7;
		}

		.f-r {
			/* padding: 17px 0; */
		}

		.mark {
			padding: 17px 15px;
		}

		.mark1 {
			padding: 17px 5px 17px 15px;
			position: relative;
		}

		.f-sub {
			color: #969799;
			font-size: 13px;
			margin-top: 4px;
		}

		.line {
			position: relative;
			width: 30px;
		}

		.line1 {
			width: 60px;
		}

		.line-sq {
			display: inline-block;
			width: 11px;
			height: 11px;
			border-radius: 6px;
			background: #d6d6d6;
			position: absolute;
			left: 0;
			top: 12px;
		}

		.line-li {
			display: inline-block;
			width: 1px;
			background: #d6d6d6;
			position: absolute;
			left: 5px;
			top: -17px;
			bottom: -17px;
		}

		.line-li1 {
			display: inline-block;
			background: #d6d6d6;
			position: absolute;
			top: 52px;
			left: 35px;
			width: 3px;
			bottom: 10px;
		}

		.pd {
			padding: 16px 0;
		}

		.ap-r {
			text-align: right;
			padding-right: 10px;
			/* margin: -8px 0; */
			padding-top: 10px;
		}

		.ap-d {
			text-align: right;
			padding-right: 10px;
			color: #ccccce;
			font-size: 13px;
			float: right;
			padding-top: 3px;
		}

		.img {
			width: 34px;
			height: 34px;
			line-height: 34px;
			text-align: center;
			font-size: 12px;
			color: #fff;
			background-color: #3396fb;
			border-radius: 6px;
			margin: 0 auto;
			position: relative;
			user-select: none;
		}

		.img1 {
			width: 44px;
			height: 44px;
			line-height: 44px;
			text-align: center;
			font-size: 13px;
			color: #fff;
			background-color: #3396fb;
			border-radius: 6px;
			position: relative;
			user-select: none;
		}

		.dis-ib {
			display: inline-block;
			vertical-align: middle;
			text-align: center;
			min-width: 40px;
		}

		.dis2-ib {
			display: inline-block;
			vertical-align: middle;
			padding-bottom: 3px;
			text-align: center;
		}

		.dis3-ib {
			display: inline-block;
			margin: 0 6px;
			color: #969799;
			vertical-align: top;
			padding-top: 7px;
			text-align: center;
		}

		.ap-n {
			padding-top: 2px;
			font-size: 13px;
			color: #969799;
			text-align: center;
		}

		.bottom {
			padding: 8px 15px;
		}

		.part-white {
			padding: 15px;
			background-color: #fff;
			position: relative;
		}

		.title {
			line-height: 40px;
			font-size: 18px;
		}

		.title-sub {
			color: #aaacac;
			font-size: 13px;
		}

		.title-read {
			color: #3396fb;
			font-size: 13px;

		}

		.title-unread {
			color: #788a8a;
			font-size: 13px;
		}

		.ap-res {
			color: #a3a3a3;
			font-size: 15px;
			padding-top: 6px;
		}

		.ap-res1 {
			color: #c31616;
			font-size: 15px;
			padding-top: 6px;
		}

		.ap-img {
			position: absolute;
			right: 20px;
			bottom: -38px;
			width: 88px;
			opacity: 0.4;
		}

		.form-row {
			padding: 4px 16px;
		}

		.form-label {
			color: #808991;
			font-size: 13px;
			user-select: none;
		}

		.form-content {
			padding-top: 5px;
		}

		.npd {
			padding-top: 0;
			overflow-x: auto;
		}

		.pl {
			color: #969799;
			font-size: 16px;
			margin: 6px 2px 18px 0;
			min-height: 25px;
			border-bottom: 1px solid #ebedf0;
		}

		.sf {
			width: 16px;
			background: #fff;
			padding: 2px;
			border-radius: 8px;
			position: absolute;
			right: -5px;
			bottom: -2px;
		}

		.select {
			color: #3396fb;
			float: right;
			font-size: 13px;
			padding-top: 3px;
			vertical-align: middle;
		}

		.select a {
			vertical-align: middle;
		}

		.select img {
			width: 16px;
			vertical-align: middle;
		}

		.hq {
			padding: 10px 10px 0 0;
		}

		.wh {

			white-space: nowrap;
			overflow-x: auto;
			padding-right: 10px;
		}

		.plpd {
			padding-bottom: 5px;
		}

		.pictitle {
			line-height: 24px;
			color: #646566;
			user-select: none;
		}

		.piccontent {
			padding-top: 10px;
			overflow: hidden;
		}

		.van-uploader__preview {
			margin-right: 15px;
		}

		.no {
			text-align: center;
			color: #808991;
			font-size: 14px;
		}

		.li1 {
			top: 15px;
		}

		.li2 {
			bottom: 24px;
		}

		.da-c {
			color: #c31616;
		}

		.danger .van-field__control {
			color: #c31616;
		}

		.danger .van-field__label {
			color: #808991;
		}

		.ac-1 {
			color: #03b553;
		}

		.ac-2 {
			color: #c31616;
		}

		.checkbox {
			padding: 25px 5px 10px 10px;
		}

		.jl-remark {
			padding: 5px 0;
			color: #3396fb;
		}

		.memo-l {
			border-bottom: 1px solid rgb(235, 237, 240);
			padding: 4px 0;
		}

		.memo-l:last-child {
			border-bottom: 0;
		}
	</style>
</head>

<body>
	<div id="app" v-cloak>
		<div class="box">
			<van-nav-bar-main title="零件质量问题录入" left-arrow @click-left="onClickLeft"></van-nav-bar-main>
			<div class="content" style="padding-bottom: 20px;">
				<div>
					<div class="part">
						<div class="pf">
							<van-field required v-model="form.CkTime" label="检验日期" placeholder="请选择检验日期" readonly
								@click="openDate(1)"></van-field>
							<van-field required v-model="form.Program" label="项目" placeholder="请输入项目"></van-field>
							<van-field required v-model="form.ProductName" label="零件名称" placeholder="零件" readonly
								right-icon="arrow" @click="openBaseScreen('零件')"></van-field>
							<van-field v-model="form.ClientName" label="投诉客户" placeholder="请选择客户" readonly
								right-icon="arrow" @click="openBaseScreen('客户')"></van-field>
							<!-- <van-cell>
								<div class="pictitle">国内国外</div>
								<div style="padding-top:5px;">
									<van-radio-group v-model="form.Range" icon-size="18px" direction="horizontal">
										<van-radio name="国内">国内</van-radio>
										<van-radio name="国外">国外</van-radio>
										<van-radio name="内部">内部</van-radio>
									</van-radio-group>
								</div>
							</van-cell> -->
							<van-field v-model="form.Range" label="发生地" placeholder="请选择发生地" readonly right-icon="arrow"
								@click="openBaseScreen('发生地')"></van-field>
							<van-field v-model="form.QualityEngineer" label="质量工程师" placeholder="请输入质量工程师"></van-field>
							<van-field v-model="form.Priority" label="问题等级" placeholder="请选择问题等级" readonly
								right-icon="arrow" @click="openSimpleScreen('问题等级')">
							</van-field>
							<van-cell>
								<div class="pictitle">整改完成</div>
								<div style="padding-top:5px;">
									<van-radio-group v-model="form.IsReform" icon-size="18px" direction="horizontal">
										<van-radio :name="true">是</van-radio>
										<van-radio :name="false">否</van-radio>
									</van-radio-group>
								</div>
							</van-cell>
							<van-field v-model="form.ResBranchName" label="主要责任部门" placeholder="请选择主要责任部门" readonly
								right-icon="arrow" @click="openBaseScreen('主要责任部门')"></van-field>
							<van-field v-model="form.SecBranchName" label="次要责任部门" placeholder="请选择次要责任部门" readonly
								right-icon="arrow" @click="openBaseScreen('次要责任部门')"></van-field>
							<van-field v-model="form.ProblemType" label="问题类型" placeholder="请选择问题类型" readonly
								right-icon="arrow" @click="openBaseScreen('问题类型')"></van-field>
							<van-field rows="2" autosize v-model="form.ProblemDescText" label="问题描述" type="textarea"
								placeholder="请输入问题描述" clearable>
								<template #button>
									<van-button v-if="recUrl" style="border: none;" plain icon="../image/voiceOn.png"
										@click="playVoice">
									</van-button>
									<!-- <van-button v-else style="border: none;" plain icon="../image/voiceOff.png">
									</van-button> -->
								</template>
							</van-field>
							<van-cell>
								<van-row type="flex" justify="center">
									<van-col span="24">
										<van-button id="audioInput" type="info" icon="../image/speaking.png"
											:text="spkBtnTxt" plain block>
										</van-button>
									</van-col>
								</van-row>
							</van-cell>
							<van-cell>
								<div class="pictitle">问题图片</div>
								<div class="piccontent">
									<div class="van-uploader">
										<div class="van-uploader__wrapper">
											<div class="van-uploader__preview"
												v-for="(imgItem,imgItemIndex) in form.ProblemDescImgArray">
												<div class="van-image van-uploader__preview-image"
													style="overflow: hidden; border-radius: 4px;"
													@click="previewImage(imgItemIndex,1)">

													<img :src="serverIP + imgItem" class="van-image__img"
														style="object-fit: cover;" />
												</div>
												<div class="van-uploader__preview-delete"
													@click="deleteImgItem(imgItemIndex)">
													<i
														class="van-icon van-icon-cross van-uploader__preview-delete-icon"></i>
												</div>

											</div>
											<div class="van-uploader__upload"
												v-if="form.ProblemDescImgArray.length < 15"
												@click="addImage(form.ProblemDescImgArray.length)">
												<i class="van-icon van-icon-plus van-uploader__upload-icon"></i>

											</div>
										</div>
									</div>
								</div>
							</van-cell>
							<van-field rows="1" autosize v-model="form.Measure" label="主要措施" type="textarea"
								placeholder="请输入主要措施">
							</van-field>
							<van-field rows="1" autosize v-model="form.SecMeasure" label="次要措施" type="textarea"
								placeholder="请输入次要措施">
							</van-field>
							<van-field rows="1" autosize v-model="form.Track" label="后续跟踪" type="textarea"
								placeholder="请输入后续跟踪">
							</van-field>
							<van-field rows="1" autosize v-model="form.FRemarks" label="备注" type="textarea"
								placeholder="请输入备注">
							</van-field>
						</div>
					</div>

				</div>

			</div>
			<div class="bottom">
				<div class="flex-main">
					<van-row gutter="30">
						<van-col :span="24">
							<van-button block :square="false" :disabled="ifConfirm" :loading="ifConfirm"
								@click="savePage">确认提交</van-button>
						</van-col>
					</van-row>
				</div>
			</div>


		</div>

		<van-popup v-model="showSimpleSelect" position="bottom">
			<van-picker show-toolbar :columns="columns" value-key="name" @cancel="showSimpleSelect = false"
				@confirm="simpleSelectChange"></van-picker>
		</van-popup>

		<van-popup v-model="showDate" position="bottom">
			<van-datetime-picker v-model="currentDate" type="date" @confirm="confirmDate" @cancel="cancelDate"
				cancel-button-text="清空" />
		</van-popup>

	</div>

	<div class="blackBoxSpeak">
		<p class="blackBoxSpeakConent">手指上划，取消发送</p>
	</div>

	<div class="blackBoxPause">
		<p class="blackBoxPauseContent" style="background: red">松开手指， 取消发送</p>
	</div>
</body>
<script type="text/javascript">
	var vm;
	apiready = function () {

		var UIAlbumBrowser = api.require('UIAlbumBrowser');
		var photoBrowser = api.require('photoBrowser');
		var isOpenImg = false;
		var iflyRecognition = api.require('iflyRecognition');	//科大讯飞原生插件
		// var audioRecorder = api.require('audioRecorder');
		var audioStreamer = api.require('audioStreamer');

		// 创建科大讯飞引擎
		iflyRecognition.createUtility({
			ios_appid: 'bdf3e525',
			android_appid: 'bdf3e525'
		}, function (ret, err) {
			if (ret.status) {
				// console.log('创建成功')
			} else {
				// console.log('创建失败')
			}
		});

		// 添加录音音量显示器
		// iflyRecognition.addRecordHUD({
		// 	// centerX: 160,
		// 	centerY: 365,
		// 	radius: 80,
		// 	transparentR: 40,
		// 	bg: '#1296db',
		// 	fixedOn: api.frameName,
		// 	fixed: false
		// }, function (ret, err) {
		// 	var volume = ret.volume;
		// });

		api.addEventListener({
			name: 'keyback'
		}, function (ret, err) {
			if (!isOpenImg) {
				vm.onClickLeft();
			} else {
				photoBrowser.close();
			}

		});

		api.addEventListener({
			name: 'selectRow'
		}, function (ret, err) {
			var type = ret.value.type;
			var row = ret.value.row;
			if (type == '零件') {
				vm.form.ProductId = row[0].ProductID;
				vm.form.ProductName = row[0].ProductName;
			}
			if (type == '客户') {
				vm.form.ClientName = row[0].name;
				vm.form.ClientID = row[0].ClientID;
			}
			if (type == '主要责任部门') {
				vm.form.ResBranchName = row[0].BranchName;
				vm.form.ResBranchID = row[0].BranchID;
			}
			if (type == '次要责任部门') {
				vm.form.SecBranchName = row[0].BranchName;
				vm.form.SecBranchID = row[0].BranchID;
			}
			if (type == '问题类型') {
				vm.form.ProblemType = row[0].ProblemType;
			}
			if (type == '发生地') {
				vm.form.Range = row[0].Range;
				// vm.problemTypeSrc = row[0].Range;
			}
		})


		vm = new Vue({
			el: '#app',
			data: {
				isRec: false,	//是否识别中
				recUrl: '',	//音频路径
				showLoading: false,
				ifConfirm: false,
				serverIP: 'http://' + APP.serverIP(),
				userData: APP.getUserInfo(),

				showSimpleSelect: false,
				SimpleSelectType: '',
				columns: [],

				currentDate: new Date(),
				showDate: false,

				// problemTypeSrc:'',	//过滤发生地对应问题类型
				form: {
					CkTime: APP.getFormatDate1(),
					Program: '',
					ProductId: 0,
					ProductName: '',
					ProblemType: '',
					ProblemDesc: '',
					ProblemDescText: '',
					ProblemAudio: '',	//问题描述音频文件
					ProblemDescImgArray: [],
					ResBranchID: 0,
					ResBranchName: '',
					SecBranchID: 0,
					SecBranchName: '',
					QualityEngineer: '',
					Measure: '',
					Track: '',
					IsReform: '',
					Priority: '',
					ClientID: 0,
					ClientName: '',
					SecMeasure: '',
					Range: ''
				},
				spkBtnTxt: '按住 说话'
			},
			created: function () {
				var that = this;
				setTimeout(function () {
					that.initAudio();
				}, 500)
			},
			methods: {

				// 初始化语音输入
				initAudio: function () {
					var that = this;
					//录音按钮
					var audioInput = document.getElementById("audioInput");

					//中间黑色边框和里面的内容（录音状态）
					var blackBoxSpeak = document.querySelector(".blackBoxSpeak");
					blackBoxSpeak.style.background = "url('../image/ic_record@2x.png')no-repeat 28 16px/65px 104px, url('../image/ic_record_ripple@2x-9.png')no-repeat 111.2px 32px/28.8px 88px";
					blackBoxSpeak.style.backgroundColor = "rgba(0,0,0,.7)";

					//中间黑色边框和里面的内容（暂停状态）
					var blackBoxPause = document.querySelector(".blackBoxPause");
					blackBoxPause.style.background = "rgba(0,0,0,.7) url('../image/ic_release_to_cancel@2x.png')no-repeat center 8px/67.2px 104px";
					blackBoxPause.style.backgroundColor = "rgba(0,0,0,.7)";

					//手指移动相关
					var posStart = 0; //初始化起点坐标
					var posEnd = 0; //初始化终点坐标
					var posMove = 0; //初始化滑动坐标

					//轮播相关
					var index = [9, 8, 7, 6, 5, 4, 3, 2, 1, 2, 3, 4, 5, 6, 7, 8, 9];
					var num = index.length;
					var timer = null; //用于清除计时器

					function initEvent() {

						audioInput.addEventListener("touchstart", function (event) {
							setTimer();
							event.preventDefault(); //阻止浏览器默认行为
							posStart = 0;
							posStart = event.touches[0].pageY; //获取起点坐标

							// 科大讯飞
							iflyRecognition.record({
								vadbos: 3000,
								vadeos: 3000,
								rate: 16000,
								asrptt: 1,
								audioPath: 'fs://speechRecogniser/speech.pcm'
							}, function (ret, err) {
								console.log(JSON.stringify(ret))
								console.log(JSON.stringify(err))

								if (api.systemType == 'ios') {
									if (ret.status) {
										if (ret.eventType == 'recognize_end') {
											if (ret.wordStr) {
												vm.form.ProblemDescText = ret.wordStr;

												setTimeout(() => {
													APP.uploadFile('part_audio', 'fs://speechRecogniser/speech.pcm', function (path) {
														var mp3_path = 'http://' + APP.serverIP() + path;
														console.log(mp3_path)
														audioStreamer.onNormal();
														audioStreamer.openPlayer({
															path: 'widget://image/chat/voice.mp3',
														}, function (ret) {

														});
														vm.recUrl = mp3_path;
													})
												}, 1000);
											}
										}
										// if (ret.eventType == 'record_end') {
										// 	if (ret.wordStr) {
										// 		APP.uploadFile('part_audio', 'fs://speechRecogniser/speech.pcm', function (path) {
										// 			var mp3_path = 'http://' + APP.serverIP() + path;
										// 			console.log(mp3_path)
										// 			audioStreamer.onNormal();
										// 			audioStreamer.openPlayer({
										// 				path: 'widget://image/chat/voice.mp3',
										// 			}, function (ret) {

										// 			});
										// 			vm.recUrl = mp3_path;
										// 		})
										// 	}
										// }

									} else {
										layer.open({
											content: err.msg,
											skin: 'msg',
											time: 2
										});
									}
								}

								if (api.systemType == 'android') {
									if (ret.status == true) {
										if (ret.wordStr) {
											vm.form.ProblemDescText = ret.wordStr;
										}
										APP.uploadFile('part_audio', 'fs://speechRecogniser/speech.pcm', function (path) {
											var mp3_path = 'http://' + APP.serverIP() + path;
											console.log(mp3_path)
											audioStreamer.onNormal();
											audioStreamer.openPlayer({
												path: 'widget://image/chat/voice.mp3',
											}, function (ret) {

											});
											vm.recUrl = mp3_path;
										})
									}
									if (ret.status == false) {
										layer.open({
											content: err.msg,
											skin: 'msg',
											time: 2
										});
									}

									if (ret.eventType == 'recognize_end') {
										showBlackBoxNone();
									}
								}

							})

							// 录音插件
							// audioRecorder.startRecord({
							// 	savePath: 'fs://voice.aac',
							// 	format: 'aac'
							// }, function (ret, err) {

							// });

							//显示录音 隐藏暂停
							showBlackBoxSpeak();

						});
						audioInput.addEventListener("touchmove", function (event) {
							event.preventDefault(); //阻止浏览器默认行为

							posMove = event.targetTouches[0].pageY; //获取滑动实时坐标
							if (posStart - posMove < 200) {
								//隐藏录音 显示暂停
								showBlackBoxSpeak();
							} else {
								//显示录音 隐藏暂停
								showBlackBoxPause();
							}
						});
						audioInput.addEventListener("touchend", function (event) {
							event.preventDefault(); //阻止浏览器默认行为
							posEnd = 0;
							posEnd = event.changedTouches[0].pageY; //获取终点坐标

							clearInterval(timer);
							//初始化状态
							initStatus();
							console.log(112232)

							if (posStart - posEnd < 200) {
								console.log('完成录制')
								//发送成功
								showBlackBoxNone();
								// setTimeout(() => {

								// if (api.systemType == 'android') {
								iflyRecognition.stopRecord();
								// }
								// }, 200);
								// setTimeout(function () {
								// 	audioRecorder.stopRecord(function (ret) {
								// 		if (ret && ret.status) {
								// 			audioRecorder.getAttr({
								// 				path: 'fs://voice.aac'
								// 			}, function (ret) {
								// 				var time = parseInt(ret.duration / 1000);
								// 				if (time) {
								// 					APP.uploadFile('part_audio', 'fs://voice.aac', function (path) {
								// 						var mp3_path = 'http://' + APP.serverIP() + path;
								// 						console.log(mp3_path)
								// 						vm.form.ProblemAudio = path;	//音频路径
								// 						audioStreamer.onNormal();
								// 						audioStreamer.openPlayer({
								// 							path: 'widget://image/chat/voice.mp3',
								// 						}, function (ret) {

								// 						});

								// 						vm.recUrl = mp3_path;

								// 						// that.sendMsg('[div mp3_src=' + mp3_path + ' voice_time=' + time + ' onclick=playmp3(this)][div class=mp3_icon][/div][div style=display:inline-block;vertical-align: middle; ]语音消息[/div][/div]');

								// 					})
								// 				}

								// 			});

								// 		}
								// 	});

								// }, 200)


							} else {
								//取消发送
								showBlackBoxNone();
								// 科大讯飞
								iflyRecognition.cancelRecord();

								// 录音插件
								// audioRecorder.stopRecord(function (ret) {

								// });
							}
						});
					}

					initEvent();

					//轮播
					function setTimer() {
						blackBoxSpeak.style.background = "url('../image/ic_record@2x.png')no-repeat 28px 16px/64px 104px, url('../image/ic_record_ripple@2x-" + index[2] + ".png')no-repeat 111.2px 32px/28.8px 88px";
						blackBoxSpeak.style.backgroundColor = " rgba(0,0,0,.7)";
					}

					//初始化状态
					var initStatus = function () {
						// audioInput.innerHTML = '按住 说话';
						vm.spkBtnTxt = '按住 说话';
						//全部隐藏
						showBlackBoxNone();
					}

					//显示录音 隐藏暂停
					var showBlackBoxSpeak = function () {
						// audioInput.innerHTML = '松开 结束';
						vm.spkBtnTxt = '松开 结束';
						blackBoxSpeak.style.display = "block";
						blackBoxPause.style.display = "none";
					}

					//隐藏录音 显示暂停
					var showBlackBoxPause = function () {
						// audioInput.innerHTML = '松开手指，取消发送';
						vm.spkBtnTxt = '松开手指，取消发送';
						blackBoxSpeak.style.display = "none";
						blackBoxPause.style.display = "block";
					}

					//隐藏录音
					var showBlackBoxNone = function () {
						blackBoxSpeak.style.display = "none";
						blackBoxPause.style.display = "none";
					}

				},

				// 播放语音
				playVoice() {
					console.log('voiceUrl', vm.recUrl)
					if (vm.recUrl) {
						audioStreamer.setVolume({
							volume: 0.6
						});
						audioStreamer.onNormal();
						audioStreamer.openPlayer({
							path: vm.recUrl,
						}, function (ret) {

						});
					}
				},

				savePage: function () {
					var that = this;
					if (!that.form.CkTime) {
						layer.open({
							content: '请选择检验日期',
							skin: 'msg',
							time: 2
						});
						return false;
					}
					if (!that.form.Program) {
						layer.open({
							content: '请选择项目',
							skin: 'msg',
							time: 2
						});
						return false;
					}
					if (!that.form.ProductId) {
						layer.open({
							content: '请选择零件',
							skin: 'msg',
							time: 2
						});
						return false;
					}

					if (that.form.IsReform === '') that.form.IsReform = false;

					var imgs = [];
					for (var i in that.form.ProblemDescImgArray) {
						imgs.push('<img src="' + that.form.ProblemDescImgArray[i] + '" />')
					}

					that.form.ProblemDesc = '<p>' + that.form.ProblemDescText + '</p>' + imgs.join();

					// alert(JSON.stringify(that.form))
					that.ifConfirm = true;

					APP.ajax('insertQuality', that.form, function (res) {
						that.ifConfirm = false;
						layer.open({
							content: '提交成功',
							skin: 'msg',
							time: 2
						});

						that.form = {
							CkTime: APP.getFormatDate1(),
							Program: '',
							ProductId: 0,
							ProductName: '',
							ProblemType: '',
							ProblemDesc: '',
							ProblemAudio: '',
							ProblemDescText: '',
							ProblemDescImgArray: [],
							ResBranchID: 0,
							ResBranchName: '',
							SecBranchID: 0,
							SecBranchName: '',
							QualityEngineer: '',
							Measure: '',
							Track: '',
							IsReform: '',
							Priority: '',
							ClientID: 0,
							ClientName: '',
							SecMeasure: '',
							Range: ''
						}


					})

				},
				openDate: function () {
					this.currentDate = new Date();
					this.showDate = true;
				},
				confirmDate: function (value) {
					this.form.CkTime = APP.getFormatDate(value).split(' ')[0]
					this.showDate = false;
				},
				cancelDate: function (value) {
					this.form.CkTime = '';
					this.showDate = false;
				},
				openSimpleScreen: function (str) {
					var that = this;
					that.SimpleSelectType = str;
					if (str == '问题等级') {
						that.columns = [{ name: '一级问题' }, { name: '二级问题' }, { name: '三级问题' }];
					}
					that.showSimpleSelect = true;
				},
				simpleSelectChange: function (value, index) {
					var that = this;
					if (that.SimpleSelectType == '问题等级') {
						that.form.Priority = that.columns[index].name;
					}

					that.showSimpleSelect = false;
				},
				previewItemImage: function (imgs, index) {
					var that = this;
					var array = imgs.split(',');
					for (var i in array) {
						array[i] = that.serverIP + array[i];
					}
					photoBrowser.open({
						images: array,
						activeIndex: index,
						bgColor: '#000'
					}, function (ret) {
						isOpenImg = true;
						if (ret) {
							if (ret.eventType == 'click') {
								isOpenImg = false;
								photoBrowser.close();
							}
						}
					})
				},
				previewImage: function (index, type) {
					var that = this;
					var array = JSON.parse(JSON.stringify(that.form.ProblemDescImgArray));
					for (var i in array) {
						array[i] = that.serverIP + array[i];
					}
					photoBrowser.open({
						images: array,
						activeIndex: index,
						bgColor: '#000'
					}, function (ret) {
						isOpenImg = true;
						if (ret) {
							if (ret.eventType == 'click') {
								isOpenImg = false;
								photoBrowser.close();
							}
						}
					})
				},
				deleteImgItem: function (index) {
					var that = this;
					that.form.ProblemDescImgArray.splice(index, 1)
				},
				addImage: function (len) {
					var that = this;
					//
					UIAlbumBrowser.imagePicker({
						max: 15 - len,
						styles: {
							nav: {
								bg: 'rgba(0,0,0,.6)',
								finishText: '完成'
							}
						},
						rotation: true
					}, function (ret) {
						if (ret) {
							if (ret.originalPath) {
								UIAlbumBrowser.transPath({
									path: ret.assetPath || ret.originalPath
								}, function (ret, err) {
									if (ret) {
										APP.uploadFile('零件质量图片', ret.path, function (path) {
											that.form.ProblemDescImgArray.push(path);
										})

									}
								});
							} else if (ret.eventType == 'nextStep') {
								UIAlbumBrowser.closePicker();
								var imgLists = ret.list;
								var repeatImg = function (i) {
									if (i == imgLists.length) {
										return;
									}
									UIAlbumBrowser.transPath({
										path: imgLists[i].path
									}, function (ret, err) {
										if (ret) {
											APP.uploadFile('零件质量图片', ret.path, function (path) {
												that.form.ProblemDescImgArray.push(path);
											})
											i++;
											repeatImg(i);
										}
									});
								}
								repeatImg(0)

							}

						}
					});
				},
				openBaseScreen: function (str) {
					var that = this;
					var obj;
					if (str == '零件') {
						obj = {

							allowClear: false,
							cmd: 'getCkProductList',
							type: str,
							// localSearch:{
							// 	showText:'',		//查询结果显示的字段
							// 	searchBy:['']		//按那些字段进行搜索
							// },
							serverSearch: {
								isPaging: true,		//是否分页
								searchKey: 'ProductName',		//搜索关键词，应包含在param中
								showText: 'ProductName',		//查询结果显示的字段
								pageIndexStr: 'pageIndex'		//分页页码字段，应包含在param中
							},
							param: {
								pageIndex: 1,
								ProductName: ''
							}

						}
					}
					if (str == '客户') {
						obj = {

							allowClear: false,
							cmd: 'app_getClientList',
							type: str,
							localSearch: {
								showText: 'name',		//查询结果显示的字段
								searchBy: ['name', 'ClientCode']		//按那些字段进行搜索
							},
							param: {

							}

						}
					}
					if (str == '主要责任部门' || str == '次要责任部门') {
						obj = {

							allowClear: false,
							cmd: 'zr_departmentlist',
							type: str,
							localSearch: {
								showText: 'BranchName',		//查询结果显示的字段
								searchBy: ['BranchName']		//按那些字段进行搜索
							},
							param: {

							}

						}
					}
					if (str == '问题类型') {
						obj = {

							allowClear: false,
							cmd: 'app_getProblemType',
							type: str,
							localSearch: {
								showText: 'ProblemType',		//查询结果显示的字段
								searchBy: ['ProblemType']		//按那些字段进行搜索
							},
							param: {
								// problemTypeSrc: vm.problemTypeSrc
							}

						}
					}
					if (str == '发生地') {
						obj = {

							allowClear: false,
							cmd: 'app_getProblemRange',
							type: str,
							localSearch: {
								showText: 'Range',		//查询结果显示的字段
								searchBy: ['Range']		//按那些字段进行搜索
							},
							param: {

							}

						}
					}
					api.openWin({
						name: 'baseScreen',
						url: 'tool/baseScreen.html',
						reload: true,
						slidBackEnabled: false,
						allowEdit: true,
						pageParam: obj
					})
				},
				onClickLeft: function () {
					var that = this;
					api.closeWin();

				}
			}
		})
	};
</script>

</html>